﻿using DTO;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DAO
{
    public class PhanQuyen_DAO
    {
        public static DataTable SelectAll()
        {
            string sql = "select * from PHANQUYEN";
            return DataAccess.executeQuery(sql);
        }
        
        public static PhanQuyen_DTO SelectByTen(string ten)
        {
            string sql = "select * from PHANQUYEN where PhanQuyen = '" + ten + "'";
            DataTable dt = DataAccess.executeQuery(sql);
            PhanQuyen_DTO dto = new PhanQuyen_DTO();
            dto.TenPQ = Convert.ToString(dt.Rows[0]["PhanQuyen"]);
            dto.QuyenPhanQuyen = Convert.ToBoolean(dt.Rows[0]["QuyenPhanQUyen"]);
            dto.QuanLy = Convert.ToBoolean(dt.Rows[0]["QuanLy"]);
            dto.ThayDoiQuyDinh = Convert.ToBoolean(dt.Rows[0]["ThayDoiQuyDinh"]);
            return dto;
        }
        public static void Insert(PhanQuyen_DTO dto)
        {
            string sql = "Insert INTO PHANQUYEN (PhanQuyen, QuyenPhanQUyen, QuanLy, ThayDoiQuyDinh)" +
                            "VALUES ('" + dto.TenPQ +
                                     "'," + dto.QuyenPhanQuyen+
                                     "," + dto.QuanLy +
                                     "," + dto.ThayDoiQuyDinh +")";
            
            DataAccess.executeNonQuery(sql);
        }
        public static void Update(PhanQuyen_DTO dto)
        {
            string sql = "Update PHANQUYEN set QuyenPhanQUyen=(" + dto.QuyenPhanQuyen +
                                            "),QuanLy=(" + dto.QuanLy +
                                            "),ThayDoiQuyDinh=(" + dto.ThayDoiQuyDinh +
                                            ") where PhanQuyen = '" + dto.TenPQ + "'";
            
            DataAccess.executeNonQuery(sql);
        }
        public static void Delete(string ten)
        {
            string sql = "Delete from PHANQUYEN where PhanQuyen = '" + ten + "'";
            DataAccess.executeNonQuery(sql);
        }
    }
}
